<?php
    $attribute = pc_variable("attribute");
    $name = pc_variable("name");
    $value = pc_variable("value");
    $currency = null;
    $amount = null;
    if($value !== null) {
        $currency = $value->get("currency");
        $amount = $value->get("value");
    }
    $errors = pc_variable("errors");
    if($errors !== null && $errors->get($name . ".currency") !== null) {
        $currency = pc_variable("entity." . $name . ".currency");
    } else {
        if($currency !== null) {
            $currency = $currency->getName();
        }
    }
    if($errors !== null && $errors->get($name . ".value") !== null) {
        $amount = pc_variable("entity." . $name . ".value");
    } else {
        if($amount !== null) {
            $amount = pc_format_number($amount, pc_message("localization.currencyFormat"));
        }
    }
?>
<label for="entity.<?php pc_echo($name); ?>.value"<?php if($attribute->isRequired()) { ?> class="required"<?php } ?>><?php pc_echo(pc_message("field." . $name)); ?></label>
<select id="entity.<?php pc_echo($name); ?>.currency" name="entity.<?php pc_echo($name); ?>.currency" class="composed">
    <option value=""></option>
    <?php foreach(Pageley_Basic_Domain_Currency::values() as $cur) { ?>
        <option value="<?php pc_echo($cur->getName()); ?>"<?php if($currency === $cur->getName()) {?> selected="selected"<?php } ?>><?php pc_echo($cur->getName()); ?></option>
    <?php } ?>
</select>
<input type="hidden" name="entity.<?php pc_echo($name); ?>.value.format" value="<?php pc_echo(pc_message("localization.currencyFormat")); ?>"/>
<input type="text" id="entity.<?php pc_echo($name); ?>.value" name="entity.<?php pc_echo($name); ?>.value" value="<?php pc_echo($amount); ?>" class="composed"/>
<br/>
<?php
pc_pagelet("common/error", array(
    "errors" => $errors,
    "name" => $name . ".currency"));
pc_pagelet("common/error", array(
    "errors" => $errors,
    "name" => $name . ".value"));
